home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
pctchnqs
/
1992
/
number2
/
vbplay
/
playnote.txt
< prev
next >
Wrap
Text File
|
1992-03-24
|
2KB
|
80 lines
Function PlayNote%(nVoice%,nNote%,nTempo%,nDuration%,nMode%,nDot%)
Static fbaseFreq(12)
Static fMode!(3)
'
' Initialize arrays first time through
'
If fbaseFreq(0) < 1 Then
fbaseFreq(0) = 65.41
fbaseFreq(1) = 69.3
fbaseFreq(2) = 73.42
fbaseFreq(3) = 77.78
fbaseFreq(4) = 82.41
fbaseFreq(5) = 87.31
fbaseFreq(6) = 92.5
fbaseFreq(7) = 98#
fbaseFreq(8) = 103.83
fbaseFreq(9) = 110#
fbaseFreq(10) = 116.54
fbaseFreq(11) = 123.47
fMode(S_STACCATO) = .75
fMode(S_NORMAL) = .875
fMode(S_LEGATO) = 1#
End If
'
' Check input values for validity
'
If nTempo% < 32 Or nTempo% > 255 Then
PlayNote% = S_SERDTP
Exit Function
End If
If nNote% < 0 Or nNote% > 84 Then
PlayNote% = S_SERBDNT
Exit Function
End If
If nDuration% < 0 Or nDuration% > 255 Then
PlayNote% = S_SERDLN
Exit Function
End If
If nMode% < 0 Or nMode% > 2 Then
PlayNote% = S_SERDMD
Exit Function
End If
'
' Calcualte note duration parameters
'
If nDot% Then dt# = (3# ^ nDot%) / (2# ^ nDot%) Else dt# = 1#
nTicks% = 80000 / nTempo% / nDuration% * fMode(nMode%) * dt#
'
' Calculate frequency and play note
'
If nNote% = 0 Then
lFreq& = &H7F000000
Else
lFreq& = fbaseFreq(nNote% Mod 12) * (2^(nNote%\12))*65535
End If
status% = SetVoiceSound(nVoice%, lFreq&, nTicks%)
If status% <> 0 Then
PlayNote% = status%
Exit Function
End If
'
' If not legato, then play a rest to fill out note length
'
If nMode% <> S_LEGATO Then
nTicks% = 80000/nTempo%/nDuration%*(1#-fMode(nMode%))*dt#
PlayNote% = SetVoiceSound(nVoice%, &H7F000000, nTicks%)
End If
End Function